package net.xuele.learn.syncHttp;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * @Author: yubo
 * @date: 18:02 2021/4/22
 * @Description: 类描述
 */
@RestController
@Slf4j
public class AsyncCallableController {

    private final TaskService taskService;

    @Autowired
    public AsyncCallableController(TaskService taskService) {
        this.taskService = taskService;
    }

    @RequestMapping(value = "/callable", method = RequestMethod.GET, produces = "text/html")
    public Callable<String> executeSlowTask() {
        log.info("Request received");
        Callable<String> callable =  taskService::execute;
        log.info("Servlet thread released");

        return callable;
    }
}
